<script type="text/javascript"><!--//--><![CDATA[//><!--

    var grid_reload = function(){
        $('#datagrid').datagrid('reload', $('#fm_search').serializeObject());
    };

    $(document).ready(function() {
        // Setup Datagrid
        var kode_pengadaan_auto = "<?php echo $kode_pengadaan_auto; ?>";
        $('#datagrid').datagrid({  
            url:gs_path+'/'+controller+'/getdata', 
            queryParams: $('#fm_search').serializeObject(),
            height:520,
            pagination:true,
            columns:[[
  			    { field : 'ck', checkbox:true, width: 40, align: 'center' },
                { field : 'kode_pengadaan', title : 'Kode Pengadaan', width : 100, sortable:true },
                { field : 'nama_pengaju', title : 'Nama Pengaju', width : 135, sortable:true },
                { field : 'nama_cost_center', title : 'Departemen', width : 250, sortable:true },
				{ field : 'tanggal_pengajuan', title : 'Tanggal Pengajuan', width : 180, sortable:true },
				{ field : 'jenis_kebutuhan', title : 'Jenis Kebutuhan', width : 150, sortable:true },
				{ field : 'uraian_pengajuan', title : 'Uraian Pengajuan', width : 250, sortable:true },
				{ field : 'tanggal_estimasi', title : 'Tanggal Estamasi', width : 250, sortable:true },
            ]]
        });
        
        
        // Setup Form
        $('#form_master').setupForm([
            { name: 'kode_pengadaan', type: 'text', size: 'medium', maxlength: 10, noempty:true },
            { name: 'nama_pengaju', type: 'text', size: 'medium', maxlength: 100, noempty:true },
            { name: 'id_cost_center_pk', type:'combo', size: 'long', data:<?php echo json_encode($it_app); ?> },
            { name: 'tanggal_pengajuan', type: 'date'  },
			{ name: 'jenis_kebutuhan', type: 'text', size: 'long', maxlength: 100, noempty:true },
			{ name: 'uraian_pengajuan',type:'textarea', size: 'long', maxlength: 250, noempty:true },
			{ name: 'tanggal_estimasi', type: 'date'  }
        ]);
        
        
        // Create Dialog
        $('#dialog_container').dialog({
            closed:true,
            modal:true,
            title: '_',
            width:600,
			height:500,
            buttons:[{
                text:'Save',
                iconCls:'icon-save',
                handler:function(){
                    $('#form_master').submitForm('/'+controller+'/ajax_post', { onComplete : function(){ $('#dialog_container').dialog('close'); $('#datagrid').datagrid('reload'); }} );
                }
            },{
                text:'Close',
                iconCls:'icon-cancel',
                handler:function(){
                    $('#dialog_container').dialog('close');
                }
            }]
        });
        
        // Set Action Button
        var buttons = [ { label: 'Add', icon: 'add', onclick: function() {
                            resetError();
                            $('#dialog_container').dialog('open');
                            $('#form_master').data('mode', 'create');
                            $('#form_master').parent().parent().parent().prev().find('.panel-title').html('Tambah Data Pengajuan');
                            $('#kode_pengadaan').readonly(true);
                            $('#kode_pengadaan, #nama_pengaju, #id_cost_center_pk,#tanggal_pengajuan,#jenis_kebutuhan,#uraian_pengajuan,#tanggal_estimasi').val('');
                            $('#kode_pengadaan').setval(kode_pengadaan_auto);
                            $('#nama_pengaju').focus();
                        } },
                        { label: 'Edit', icon: 'edit', onclick: function() {
                            var oSel=$('#datagrid').datagrid('getSelected'); 
                            if(oSel==null){ 
                                alert('Please select row!'); 
                            } else{ 
                                resetError();
                                $('#dialog_container').dialog('open'); 
                                $('#form_master').data('mode', 'edit');
                                $('#form_master').parent().parent().parent().prev().find('.panel-title').html('Edit Data Perangkat');
                                $('#kode_pengadaan').readonly();
                                jsonToForm(oSel); 
                                $('#kode_pengadaan').focus();
                            } 
                        } },
                        {label: 'Delete', icon: 'delete', onclick: function() { 
                            var oSel = $('#datagrid').datagrid('getSelected'); 
                            if (oSel == null) { 
                                $.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
                            } else { 
                                deleteData(['kode_pengadaan']);
                            } 
                        }}];
        setAction(buttons);
        
        
        $('#fm_search').focusFirst();
    });
//--><!]]></script>

<div id="tb" style="padding:5px;height:auto">
    <div>
        <form id="fm_search" onsubmit="grid_reload(); return false;">
            <table class="tb_form" style="margin-bottom:0px">
            <tr>
                <td width="100">Keyword</td>
                <td><input type="text" id="keyword" name="keyword" class="textfield medium" />
                    <a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="grid_reload(); return false;">Search</a>
                </td>
            </tr>
            </table>
        </form>
    </div>
</div>
<div id="datagrid" toolbar="#tb"></div>


<div id="dialog_container" style="padding:5px;width:600px;height:250px;">
    <form id="form_master">
    <table class="tb_form" style="width:100%;" cellpadding="0" cellspacing="0">
     <tr>
        <td class="label" style="width:150px">Kode Pengadaan</td>
        <td><input id="kode_pengadaan" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Nama Pengaju</td>
        <td><input id="nama_pengaju" /></td>
    </tr>
    <tr>
        <td class="label">Department</td>
        <td><input id="id_cost_center_pk" /></td>
    </tr>
    <tr>
        <td class="label">Tanggal Pengajuan</td>
        <td><input id="tanggal_pengajuan" /></td>
    </tr>
    <tr>
        <td class="label">Jenis Kebutuhan</td>
        <td><input id="jenis_kebutuhan" /></td>
    </tr>
    <tr>
        <td class="label">Uraian Pengajuan</td>
        <td><input id="uraian_pengajuan" /></td>
    </tr>
    <tr>
        <td class="label">Estimasi Ketersediaan Permintaan</td>
        <td><input id="tanggal_estimasi" /></td>
    </tr>
    </table>
    </form>
</div>